var fruitObj=function(){
	this.alive=[];//是否活着
	this.orange=new Image();
	this.blue=new Image();
	this.x=[];
	this.y=[];
	this.l=[];//图片的长度
	this.spd=[];//果实成长,运动的速度
	this.fruitType=[];//果实类型
	this.aneNo=[];
}


fruitObj.prototype.num=30;
fruitObj.prototype.init=function(){
	for (var i=0;i<this.num;i++) {
		this.alive[i]=false;
		this.x[i]=0;
		this.y[i]=0;
		this.spd[i]=Math.random()*0.01+0.003;//每个果实的速度都不同
//		this.born(i);//初始化时让所有的果实都出生
		this.fruitType[i]=" ";
		this.aneNo[i]=0;
		
	}
	this.orange.src="src/fruit.png";
	this.blue.src="src/blue.png";
}

fruitObj.prototype.draw=function(){
	for (var i = 0; i < this.num; i++) {
		//找到一个海葵，长，飘
		if (this.alive[i]) {
			
			if (this.fruitType[i]=="blue") {
				var pic=this.blue;
			} else{
				var pic=this.orange; 
			}
			
			if (this.l[i]<=16) {
				
				var NO=this.aneNo[i];
				this.x[i]=ane.headx[NO];
				this.y[i]=ane.heady[NO];
			this.l[i]+=this.spd[i]*deltaTime;//控制海葵的由小变大
			
		}
		else{
			this.y[i]-=this.spd[i]*7*deltaTime;
			
		}
		ctx2.drawImage(pic,this.x[i]-this.l[i]*0.5,this.y[i]-this.l[i]*0.5,this.l[i],this.l[i]);
				
		
	    if(this.y[i]<10){
	    	this.alive[i]=false;
	    }
		}
	}
}
fruitObj.prototype.born=function(i){
	//随机找一个海葵
//	var aneId=Math.floor(Math.random()*ane.num);
	//果实的坐标
//	this.x[i]=ane.headx[aneId];
//	this.y[i]=ane.heady[aneId];

	this.aneNo[i]=Math.floor(Math.random()*ane.num);
	this.l[i]=0;
	this.alive[i]=true;
	var ran=Math.random();
	if(ran<0.3){
		this.fruitType[i]="blue";
	}else {
		this.fruitType[i]="orange";
	}
}

fruitObj.prototype.update=function(){
	var num=0;
	for (var i=0;i<this.num;i++) {
		if (this.alive[i]) {
			num++;
		}
	}
}

fruitObj.prototype.dead=function(i){
	//果实死亡检测
	this.alive[i]=false;
}


function fruitMonitor(){
	var num=0;
	for (var i=0;i<fruit.num;i++) {
		if (fruit.alive[i]) {
			num++;
		}
	}
	if (num<15) {
			sendFruit();
			return;
		}
}

function sendFruit(){
	for (var i = 0; i < fruit.num; i++) {
		if (!fruit.alive[i]) {
			fruit.born(i);
			return;
		}
	}
}
